package cn.edu.jxau.framework.dao.core;


import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.List;
import java.util.Properties;

import javax.sql.DataSource;

import cn.edu.jxau.core.util.druip.DataSourceUtil;


public class jdbcUtils {
    
	
	
    public static Connection getConnection(){
    	InputStream in = null; 
    	URL url = jdbcUtils.class.getClassLoader().getResource("dbconfig.properties");
        try {
			in = url.openStream();
		} catch (IOException e1) {
			e1.printStackTrace();
		}
        
    	Properties config = new Properties();
    	try {
			config.load(new InputStreamReader(in, "utf-8"));
		} catch (IOException e) {
			e.printStackTrace();
		}
        Connection conn = null;
        try {
			conn = DataSourceUtil.getInstance(config).getConnection();
		} catch (SQLException e) {
			e.printStackTrace();
		}
        return conn;
       
    }
    
    public static <T> void initParameter(PreparedStatement pstmt, List<T> params) throws SQLException{
        
        for(int i = 0; i < params.size(); i++) {
          
            pstmt.setObject(i+1, params.get(i));    
        }
        
    }
    
    public static void getMetaData(Connection conn){
        
    }
}
